package com.example.alipaydemo.Configuration;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.example.alipaydemo.Utils.GlobalBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GlobalConfiguration {

    @Bean
    public AlipayClient getAlipayTradePagePayRequest(@Autowired GlobalBean globalBean) throws AlipayApiException {
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(globalBean.getServerUrl());
        alipayConfig.setAppId(globalBean.getAppId());
        alipayConfig.setPrivateKey(globalBean.getPrivateKey());
        alipayConfig.setFormat(globalBean.getFormat());
        alipayConfig.setAlipayPublicKey(globalBean.getAlipayPublicKey());
        alipayConfig.setCharset(globalBean.getCharset());
        alipayConfig.setSignType(globalBean.getSignType());
        return new DefaultAlipayClient(alipayConfig);
    }

}
